#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define MODULUS 2147483647
#define NUM_CARDS 27
#define MIN_PLAYERS 2
#define PLAYER_RANGE 3 /* difference between max and min players +1 */

int generateGameState(long seed, struct gameState *G){
  int numPlayers;
  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
      sea_hag, tribute, smithy};

  PutSeed(seed);
  numPlayers = floor(Random() * PLAYER_RANGE) + MIN_PLAYERS;

  //Initialize all the gameState variables to random values
  initializeGame(numPlayers, k, seed, G);

  return 0;
}

int testCard(int card){
  if(card == sea_hag || card == salvager || card == treasure_map || 
     card == cutpurse || card == baron || card == smithy || card == remodel || 
     card == gardens || card == feast){
    assert(getCost(card) == 4);
    return 0;
  }
  if(card == curse || card == copper){
    assert(getCost(card) == 0);
    return 0;
  }
  else if(card == embargo || card == estate){
    assert(getCost(card) == 2);
    return 0;
  }
  else if(card == silver || card == village || card == great_hall || 
	  card == steward || card == ambassador){
    assert(getCost(card) == 3);
    return 0;
  }
  if(card == outpost || card == tribute || card == minion || card == mine ||
     card == council_room || card == duchy){
    assert(getCost(card) == 5);
    return 0;
  }
  else if(card == gold || card == adventurer){
    assert(getCost(card) == 6);
    return 0;
  }
  else if(card == province){
    assert(getCost(card) == 8);
    return 0;
  }
  else{
    return 1;
  }
}

int main(){
  int result, i, card;
  long seed = floor(Random() * MODULUS);
  
  result = 0;
  PutSeed(seed);
  //test will be conducted 2000 times
  for(i = 0; i < 2000; i++){
  //generate a random number for a random card
    card = floor(Random() * NUM_CARDS);
    result += testCard(card);
  }      
  
  //print off the results of all tests
  printf ("\n***TESTS COMPLETE***\n***SUMMARY\n***Successful Tests: %d\n***Failed Tests: %d\n\n", 2000-result, result);
  
  return 0;
}
